import { history } from 'umi';
import { getQueryValue, getEnvURL } from './utils';
export const baseRender = (oldRender) => {
  const auth = sessionStorage.getItem('author');
  const url = getEnvURL();
  const menuData = JSON.parse(sessionStorage.getItem('menuData'));
  const { hash } = window.location;
  if (!url) {
    if (!auth) {
      history.push('/base/carbon/carbonTrade');
    } else if (hash == '#/') {
      const getMenuItem =
        menuData[0] && menuData[0]['children'] ? menuData[0]['children'] : null;
      const firtPaht = getMenuItem && getMenuItem[0]?.path;
      firtPaht && history.push(firtPaht);
    } else {
      history.push(hash.split('#')[1]);
    }
  } else {
    if (!auth) {
      window.location.href = url;
    } else if (hash == '#/') {
      const getMenuItem =
        menuData && menuData[0] && menuData[0]['children']
          ? menuData[0]['children']
          : null;
      const firtPaht = getMenuItem && getMenuItem[0]?.path;
      sessionStorage.setItem('businessCode', getMenuItem[0]?.businessCode);
      firtPaht && history.push(firtPaht);
    } else {
      history.push(hash.split('#')[1]);
    }
  }

  oldRender();
};
